package base.thread.pool;

import java.util.concurrent.ExecutorService;
import java.util.concurrent.Executors;

public class TestThreadPool {
	public static void main(String[] args) {
		ExecutorService exec = Executors.newFixedThreadPool(2);
		for (int i = 0; i < 100; i++) {
			Runner runner = new Runner(i);
			exec.execute(runner);
		}
		exec.shutdown();
	}
}

class Runner implements Runnable {
	private int index;

	public Runner(int index) {
		this.index = index;
	}

	public void run() {
		long time = (long) (Math.random() * 1000);
		System.out.println("线程： " + Thread.currentThread().getName() + "（目标对象"
				+ index + "）" + ":sleeping" + time + "ms");
		try {
			Thread.sleep(time);
		} catch (Exception e) {
		}
	}
}
